// exports.AL_Framework_Bundle_Manager = void 0;
// var $macros = require("./AL_Framework_Macros");
// var n = (function () {
//     function e() {}
//     e.Instance = function () {
//         return this._instance || (this._instance = new e());
//     };
//     e.prototype.panduanShfouWeiYinqingNeibuBao = function (e) {
//         return (
//             e == cc.AssetManager.BuiltinBundleName.INTERNAL ||
//             e == cc.AssetManager.BuiltinBundleName.MAIN ||
//             e == cc.AssetManager.BuiltinBundleName.RESOURCES ||
//             e == cc.AssetManager.BuiltinBundleName.START_SCENE
//         );
//     };
//     e.prototype.remove_Loaded_Bundle = function (e) {
//         var t = this;
//         var o = [];
//         cc.assetManager.bundles.forEach(function (e, i) {
//             if (!t.panduanShfouWeiYinqingNeibuBao(i)) {
//                 o.push(i);
//             }
//         });
//         for (var i = o.length; i--; ) {
//             var n = o[i];
//             if (-1 == e.indexOf(n)) {
//                 var a = this.getBundle(n);
//                 if (a) {
//                     Manager.cacheManager.removeBundle(n);
//                     Manager.releaseManager.removeBundle(a);
//                 }
//             }
//         }
//     };
//     e.prototype.getBundle = function (e) {
//         return e ? ("string" == typeof e ? cc.assetManager.getBundle(e) : e) : null;
//     };
//     e.prototype.huoquZiyuanbaoMingzi = function (e) {
//         return e ? ("string" == typeof e ? e : e.name) : (Log.e("输入参数错误 : " + e), $macros.Macro.UNKNOWN);
//     };
//     e.prototype.loadBundle = function (e) {
//         if (this.getBundle(e.bundle)) {
//             Log.d(e.bundle + "已经加载在缓存中，直接使用");
//             Manager.releaseManager.chuli_jiazai_ziyuanbao(e.bundle);
//             return void (e.completed && e.completed());
//         }
//         Log.d("loadBundle : " + e.bundle, "item.option: " + e.option);
//         cc.assetManager.loadBundle(e.url ? e.url + "/" + e.bundle : e.bundle, e.option, function (t) {
//             t
//                 ? (Log.e("load bundle : " + e.bundle + " fail !!!"), e.error && e.error(t))
//                 : (Manager.releaseManager.chuli_jiazai_ziyuanbao(e.bundle),
//                   Log.d("load bundle : " + e.bundle + " success !!!"),
//                   e.completed && e.completed());
//         });
//     };
//     e.prototype.print = function (e) {
//         if (e) {
//             var t = [];
//             cc.assetManager.bundles.forEach(function (e) {
//                 t.push(e);
//             });
//             e.print({
//                 loaded: t
//             });
//         }
//     };
//     e._instance = null;
//     return e;
// })();
// exports.AL_Framework_Bundle_Manager = n;


exports.AL_Framework_Bundle_Manager = void 0;
const $macros = require("./AL_Framework_Macros");

class AL_Framework_Bundle_Manager {
    constructor() {}

    static Instance() {
        if (!this._instance) {
            this._instance = new AL_Framework_Bundle_Manager();
        }
        return this._instance;
    }

    // /**
    //  * 判断是否为引擎的内置包
    //  * @param {string} bundleName 包名
    //  * @returns {boolean} 是否为引擎内置包
    //  */
    // panduanShfouWeiYinqingNeibuBao(bundleName) {
    //     return (
    //         bundleName === cc.AssetManager.BuiltinBundleName.INTERNAL ||
    //         bundleName === cc.AssetManager.BuiltinBundleName.MAIN ||
    //         bundleName === cc.AssetManager.BuiltinBundleName.RESOURCES ||
    //         bundleName === cc.AssetManager.BuiltinBundleName.START_SCENE
    //     );
    // }

    // /**
    //  * 移除已加载的非引擎内置包
    //  * @param {Array<string>} keepBundles 要保留的包名数组
    //  */
    // remove_Loaded_Bundle(keepBundles) {
    //     const bundlesToRemove = [];

    //     cc.assetManager.bundles.forEach((bundle, bundleName) => {
    //         if (!this.panduanShfouWeiYinqingNeibuBao(bundleName)) {
    //             bundlesToRemove.push(bundleName);
    //         }
    //     });

    //     for (let i = bundlesToRemove.length - 1; i >= 0; i--) {
    //         const bundleName = bundlesToRemove[i];
    //         if (keepBundles.indexOf(bundleName) === -1) {
    //             const bundle = this.getBundle(bundleName);
    //             if (bundle) {
    //                 Manager.cacheManager.removeBundle(bundleName);
    //                 Manager.releaseManager.removeBundle(bundle);
    //             }
    //         }
    //     }
    // }

    /**
     * 获取包
     * @param {string|cc.AssetManager.Bundle} bundle 要获取的包名或包对象
     * @returns {cc.AssetManager.Bundle|null} 包对象
     */
    getBundle(bundle) {
        return bundle ? (typeof bundle === "string" ? cc.assetManager.getBundle(bundle) : bundle) : null;
    }

    /**
     * 获取包名
     * @param {string|cc.AssetManager.Bundle} bundle 要获取包名的包对象或包名
     * @returns {string} 包名
     */
    huoquZiyuanbaoMingzi(bundle) {
        return bundle ? (typeof bundle === "string" ? bundle : bundle.name) : (Log.e("输入参数错误 : " + bundle), $macros.Macro.UNKNOWN);
    }

    /**
     * 加载包
     * @param {Object} params 包加载参数
     * @param {string} params.bundle 包名
     * @param {string} [params.url] 包URL
     * @param {Object} [params.option] 加载选项
     * @param {Function} [params.completed] 加载完成回调
     * @param {Function} [params.error] 加载错误回调
     */
    loadBundle(params) {
        const { bundle, url, option, completed, error } = params;

        if (this.getBundle(bundle)) {
            Log.d(`${bundle}已经加载在缓存中，直接使用`);
            Manager.releaseManager.chuli_jiazai_ziyuanbao(bundle);
            if (completed) completed();
            return;
        }

        Log.d(`loadBundle : ${bundle}`, `item.option: ${option}`);
        cc.assetManager.loadBundle(url ? `${url}/${bundle}` : bundle, option, (err) => {
            if (err) {
                Log.e(`load bundle : ${bundle} fail !!!`);
                if (error) error(err);
            } else {
                Manager.releaseManager.chuli_jiazai_ziyuanbao(bundle);
                Log.d(`load bundle : ${bundle} success !!!`);
                if (completed) completed();
            }
        });
    }

    /**
     * 打印加载的包
     * @param {Object} logger 打印对象
     */
    print(logger) {
        if (logger) {
            const loadedBundles = [];
            cc.assetManager.bundles.forEach((bundle) => {
                loadedBundles.push(bundle);
            });
            logger.print({ loaded: loadedBundles });
        }
    }
}

AL_Framework_Bundle_Manager._instance = null;
exports.AL_Framework_Bundle_Manager = AL_Framework_Bundle_Manager;
